'''
https://leetcode.cn/problems/bitwise-and-of-numbers-range/description/?envType=study-plan-v2&envId=top-interview-150
'''


class Solution:
    # left : vvvvvvvvvv0xxxxxxxxxx
    # right: vvvvvvvvvv1yyyyyyyyyy
    # x[i]与y[i]可能相同，可能不同。
    # v[i]完全相同
    # 本质就是找到最高位不同的地方
    # 然后在这之前，就是整个区间都有1的地方
    def rangeBitwiseAnd(self, left: int, right: int) -> int:
        while left < right:
            right = right & (right - 1)
        return right


left = 4
right = 5
print(Solution().rangeBitwiseAnd2(left, right))